<template>
  <Dialog :title="dialogTitle" v-model="dialogVisible" width="1280" class="business-form-dialog">
    <div class="dialog-content">
      <!-- 头部区域 -->
      <div class="dialog-header">
        <div class="header-icon">
          <Icon icon="ep:briefcase" />
        </div>
        <div class="header-content">
          <h3 class="dialog-title">{{ dialogTitle }}</h3>
          <p class="dialog-subtitle">配置商机基本信息和产品清单</p>
        </div>
      </div>

      <!-- 表单区域 -->
      <div class="form-container">
        <el-form
          ref="formRef"
          :model="formData"
          :rules="formRules"
          label-width="120px"
          v-loading="formLoading"
          class="enhanced-form"
        >
          <!-- 基本信息 -->
          <div class="form-section">
            <div class="section-header">
              <Icon icon="ep:briefcase" class="section-icon" />
              <span class="section-title">基本信息</span>
            </div>

            <div class="form-grid">
              <el-form-item label="商机名称" prop="name" class="form-item">
                <div class="input-wrapper">
                  <Icon icon="ep:briefcase" class="input-icon" />
                  <el-input
                    v-model="formData.name"
                    placeholder="请输入商机名称"
                    class="enhanced-input"
                  />
                </div>
              </el-form-item>

              <el-form-item label="负责人" prop="ownerUserId" class="form-item">
                <div class="select-wrapper">
                  <Icon icon="ep:user" class="select-icon" />
                  <el-select
                    filterable
                    v-model="formData.ownerUserId"
                    :disabled="formType !== 'create'"
                    class="enhanced-select"
                    placeholder="请选择负责人"
                  >
                    <el-option
                      v-for="item in userOptions"
                      :key="item.id"
                      :label="item.nickname"
                      :value="item.id"
                    />
                  </el-select>
                </div>
              </el-form-item>

              <el-form-item label="客户名称" prop="customerId" class="form-item">
                <div class="select-wrapper">
                  <el-select-v2
                    filterable
                    :options="customerList"
                    :disabled="formData.customerDefault"
                    v-model="formData.customerId"
                    placeholder="请选择客户"
                    class="enhanced-select-v2"
                    :props="{
                      value: 'id',
                      label: 'name'
                    }"
                    clearable
                  />
                </div>
              </el-form-item>
            </div>
          </div>

          <!-- 商机配置 -->
          <div class="form-section">
            <div class="section-header">
              <Icon icon="ep:setting" class="section-icon" />
              <span class="section-title">商机配置</span>
            </div>

            <div class="form-grid">
              <el-form-item
                label="商机状态组"
                prop="statusTypeId"
                class="form-item status-group-item"
              >
                <div class="status-group-wrapper">
                  <div class="select-wrapper">
                    <Icon icon="ep:collection-tag" class="select-icon" />
                    <el-select
                      filterable
                      v-model="formData.statusTypeId"
                      placeholder="请选择商机状态组"
                      clearable
                      class="enhanced-select status-select"
                      :disabled="formType !== 'create'"
                    >
                      <el-option
                        v-for="item in statusTypeList"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id"
                      />
                    </el-select>
                  </div>
                  <el-button
                    @click="openAddStatusGroup('create')"
                    class="add-status-btn"
                    type="primary"
                    size="small"
                  >
                    <Icon icon="ep:plus" class="btn-icon" />
                    新增状态组
                  </el-button>
                </div>
              </el-form-item>

              <el-form-item label="预计成交日期" prop="dealTime" class="form-item">
                <div class="date-wrapper">
                  <Icon icon="ep:calendar" class="date-icon" />
                  <el-date-picker
                    v-model="formData.dealTime"
                    type="date"
                    value-format="x"
                    placeholder="选择预计成交日期"
                    class="enhanced-date-picker"
                  />
                </div>
              </el-form-item>

              <el-form-item label="备注" prop="remark" class="form-item">
                <div class="textarea-wrapper">
                  <Icon icon="ep:document" class="textarea-icon" />
                  <el-input
                    type="textarea"
                    v-model="formData.remark"
                    placeholder="请输入备注"
                    class="enhanced-textarea"
                    :rows="3"
                  />
                </div>
              </el-form-item>
            </div>
          </div>

          <!-- 产品清单 -->
          <div class="form-section product-section">
            <div class="section-header">
              <Icon icon="ep:goods" class="section-icon" />
              <span class="section-title">产品清单</span>
            </div>

            <ContentWrap class="product-content">
              <el-tabs v-model="subTabsName" class="enhanced-tabs">
                <el-tab-pane label="产品清单" name="product">
                  <div class="product-form-wrapper">
                    <BusinessProductForm
                      ref="productFormRef"
                      :products="formData.products"
                      :disabled="disabled"
                    />
                  </div>
                </el-tab-pane>
              </el-tabs>
            </ContentWrap>
          </div>

          <!-- 价格信息 -->
          <div class="form-section price-section">
            <div class="section-header">
              <Icon icon="ep:money" class="section-icon" />
              <span class="section-title">价格信息</span>
            </div>

            <div class="form-grid">
              <el-form-item label="产品总金额" prop="totalProductPrice" class="form-item">
                <div class="price-wrapper">
                  <Icon icon="ep:money" class="price-icon" />
                  <el-input
                    disabled
                    v-model="formData.totalProductPrice"
                    :formatter="erpPriceInputFormatter"
                    class="enhanced-input price-input"
                    placeholder="0.00"
                  />
                  <span class="price-unit">元</span>
                </div>
              </el-form-item>

              <el-form-item label="整单折扣（%）" prop="discountPercent" class="form-item">
                <div class="number-wrapper">
                  <Icon icon="ep:discount" class="number-icon" />
                  <el-input-number
                    v-model="formData.discountPercent"
                    placeholder="请输入整单折扣"
                    controls-position="right"
                    :min="0"
                    :precision="2"
                    class="enhanced-number"
                  />
                </div>
              </el-form-item>

              <el-form-item label="折扣后金额" prop="price" class="form-item">
                <div class="price-wrapper">
                  <Icon icon="ep:money" class="price-icon" />
                  <el-input
                    disabled
                    v-model="formData.totalPrice"
                    placeholder="0.00"
                    :formatter="erpPriceInputFormatter"
                    class="enhanced-input price-input final-price"
                  />
                  <span class="price-unit">元</span>
                </div>
              </el-form-item>
            </div>
          </div>
        </el-form>
      </div>
    </div>

    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogVisible = false" class="cancel-btn">
          <Icon icon="ep:close" class="btn-icon" />
          取消
        </el-button>
        <el-button @click="submitForm" type="primary" :disabled="formLoading" class="confirm-btn">
          <Icon icon="ep:check" class="btn-icon" />
          确定
        </el-button>
      </div>
    </template>
  </Dialog>

  <!-- 新增状态组表单弹窗：添加/修改 -->
  <BusinessStatusForm ref="addStatusGroupFormRef" @success="getBusinessStatusTypeSimpleListFn" />
</template>

<script setup lang="ts">
import * as BusinessApi from '@/api/crm/business'
import * as BusinessStatusApi from '@/api/crm/business/status'
import * as CustomerApi from '@/api/crm/customer'
import * as UserApi from '@/api/system/user'
import { useUserStore } from '@/store/modules/user'
import BusinessProductForm from './components/BusinessProductForm.vue'
import { erpPriceMultiply, erpPriceInputFormatter } from '@/utils'
import BusinessStatusForm from './status/BusinessStatusForm.vue'

const { t } = useI18n() // 国际化
const message = useMessage() // 消息弹窗

// 新增状态组
const addStatusGroupFormRef = ref()
const openAddStatusGroup = (type: string, id?: number) => {
  addStatusGroupFormRef.value.open(type, id)
}

const dialogVisible = ref(false) // 弹窗的是否展示
const dialogTitle = ref('') // 弹窗的标题
const formLoading = ref(false) // 表单的加载中：1）修改时的数据加载；2）提交的按钮禁用
const formType = ref('') // 表单的类型：create - 新增；update - 修改
const formData = ref({
  id: undefined,
  name: undefined,
  customerId: undefined,
  ownerUserId: undefined,
  statusTypeId: undefined,
  dealTime: undefined,
  discountPercent: 0,
  totalProductPrice: undefined,
  totalPrice: undefined,
  remark: undefined,
  products: [],
  contactId: undefined,
  customerDefault: false
})
const formRules = reactive({
  name: [{ required: true, message: '商机名称不能为空', trigger: 'blur' }],
  customerId: [{ required: true, message: '客户不能为空', trigger: 'blur' }],
  ownerUserId: [{ required: true, message: '负责人不能为空', trigger: 'blur' }],
  statusTypeId: [{ required: true, message: '商机状态组不能为空', trigger: 'blur' }]
})
const formRef = ref() // 表单 Ref
const userOptions = ref<UserApi.UserVO[]>([]) // 用户列表
const statusTypeList = ref([]) // 商机状态类型列表
const customerList = ref([]) // 客户列表的数据

/** 子表的表单 */
const subTabsName = ref('product')
const productFormRef = ref()

/** 计算 discountPrice、totalPrice 价格 */
watch(
  () => formData.value,
  (val) => {
    if (!val) {
      return
    }
    const totalProductPrice = val.products.reduce((prev, curr) => prev + curr.totalPrice, 0)
    const discountPrice =
      val.discountPercent != null
        ? erpPriceMultiply(totalProductPrice, val.discountPercent / 100.0)
        : 0
    const totalPrice = totalProductPrice - discountPrice
    // 赋值
    formData.value.totalProductPrice = totalProductPrice.toFixed(2)
    formData.value.totalPrice = totalPrice.toFixed(2)
  },
  { deep: true }
)

/** 打开弹窗 */
const open = async (
  type: string,
  id?: number,
  customerId?: number,
  contactId?: number,
  businessNameId?: number
) => {
  dialogVisible.value = true
  dialogTitle.value = t('action.' + type)
  formType.value = type
  resetForm()
  // 获得客户列表
  customerList.value = await CustomerApi.getCustomerSimpleList()
  // 修改时，设置数据
  if (id) {
    formLoading.value = true
    try {
      formData.value = await BusinessApi.getBusiness(id)
    } finally {
      formLoading.value = false
    }
  } else {
    if (businessNameId) {
      formData.value.customerId = businessNameId
      formData.value.customerDefault = true // 默认客户的选择，不允许变
    }
    // 自动关联 contactId 联系人编号
    if (contactId) {
      formData.value.contactId = contactId
    }
  }
  // 加载商机状态类型列表
  // statusTypeList.value = await BusinessStatusApi.getBusinessStatusTypeSimpleList()
  getBusinessStatusTypeSimpleListFn()
  // 获得用户列表
  userOptions.value = await UserApi.getSimpleUserList()
  // 默认新建时选中自己
  if (formType.value === 'create') {
    formData.value.ownerUserId = useUserStore().getUser.id
  }
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗

const getBusinessStatusTypeSimpleListFn = async () => {
  statusTypeList.value = await BusinessStatusApi.getBusinessStatusTypeSimpleList()
}

/** 提交表单 */
const emit = defineEmits(['success']) // 定义 success 事件，用于操作成功后的回调
const submitForm = async () => {
  // 校验表单
  if (!formRef) return
  const valid = await formRef.value.validate()
  if (!valid) return
  await productFormRef.value.validate()
  // 提交请求
  formLoading.value = true
  try {
    const data = formData.value as unknown as BusinessApi.BusinessVO
    if (formType.value === 'create') {
      await BusinessApi.createBusiness(data)
      message.success(t('common.createSuccess'))
    } else {
      await BusinessApi.updateBusiness(data)
      message.success(t('common.updateSuccess'))
    }
    dialogVisible.value = false
    // 发送操作成功的事件
    emit('success')
  } finally {
    formLoading.value = false
  }
}

/** 重置表单 */
const resetForm = () => {
  formData.value = {
    id: undefined,
    name: undefined,
    customerId: undefined,
    ownerUserId: undefined,
    statusTypeId: undefined,
    dealTime: undefined,
    discountPercent: 0,
    totalProductPrice: undefined,
    totalPrice: undefined,
    remark: undefined,
    products: [],
    contactId: undefined,
    customerDefault: false
  }
  formRef.value?.resetFields()
}
</script>

<style lang="scss" scoped>
.business-form-dialog {
  :deep(.el-dialog) {
    border-radius: 12px;
    overflow: hidden;

    @media (max-width: 768px) {
      width: 95% !important;
      margin: 20px auto;
      max-height: 90vh;
    }
  }

  :deep(.el-dialog__header) {
    display: none;
  }

  :deep(.el-dialog__body) {
    padding: 0;
    max-height: 80vh;
    overflow-y: auto;
  }

  :deep(.el-dialog__footer) {
    padding: 0;
    border-top: 1px solid #e5e7eb;
  }
}

.dialog-content {
  background: #f8fafc;
}

/* 对话框头部 */
.dialog-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 24px;
  background: linear-gradient(135deg, #0052cc 0%, #1d4ed8 100%);
  color: white;
  border-radius: 10px;

  @media (max-width: 768px) {
    padding: 16px;
    flex-direction: column;
    text-align: center;
    gap: 12px;
  }
}

.header-icon {
  width: 48px;
  height: 48px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;

  @media (max-width: 768px) {
    width: 40px;
    height: 40px;
    font-size: 18px;
  }
}

.header-content {
  flex: 1;
}

.dialog-title {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 4px 0;

  @media (max-width: 768px) {
    font-size: 16px;
  }
}

.dialog-subtitle {
  font-size: 14px;
  opacity: 0.9;
  margin: 0;

  @media (max-width: 768px) {
    font-size: 12px;
  }
}

/* 表单容器 */
.form-container {
  background: white;
  padding: 24px;

  @media (max-width: 768px) {
    padding: 16px;
  }
}

.enhanced-form {
  :deep(.el-form-item__label) {
    font-weight: 500;
    color: #374151;
    font-size: 14px;

    @media (max-width: 768px) {
      font-size: 13px;
    }
  }
}

/* 表单区域 */
.form-section {
  margin-bottom: 24px;
  padding: 20px;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid #e5e7eb;

  @media (max-width: 768px) {
    margin-bottom: 16px;
    padding: 16px;
  }

  &.product-section {
    background: white;
    border: 2px solid #e5e7eb;
  }

  &.price-section {
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    border: 2px solid #0ea5e9;
  }
}

.section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid #0052cc;
}

.section-icon {
  color: #0052cc;
  font-size: 16px;
}

.section-title {
  font-size: 16px;
  font-weight: 600;
  color: #374151;
}

/* 表单网格 */
.form-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;

  @media (max-width: 1200px) {
    grid-template-columns: repeat(2, 1fr);
  }

  @media (max-width: 768px) {
    grid-template-columns: 1fr;
    gap: 16px;
  }
}

:deep(.form-item) {
  margin-bottom: 0;
  .el-form-item__content {
    align-items: flex-start;
  }
  &.status-group-item {
    grid-column: 1 / -1;

    @media (max-width: 768px) {
      grid-column: 1;
    }
  }
}

/* 输入框样式 */
.input-wrapper,
.select-wrapper,
.date-wrapper,
.textarea-wrapper,
.price-wrapper,
.number-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.input-icon,
.select-icon,
.date-icon,
.textarea-icon,
.price-icon,
.number-icon {
  position: absolute;
  left: 12px;
  color: #6b7280;
  font-size: 16px;
  z-index: 1;
}

.textarea-icon {
  top: 12px;
}

.enhanced-input,
.enhanced-select,
.enhanced-select-v2,
.enhanced-date-picker,
.enhanced-textarea,
.enhanced-number {
  width: 100%;

  :deep(.el-input__wrapper) {
    padding-left: 40px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    transition: all 0.2s ease;
    min-height: 40px;

    &:hover {
      box-shadow: 0 4px 12px rgba(0, 82, 204, 0.1);
    }

    &.is-focus {
      box-shadow: 0 4px 12px rgba(0, 82, 204, 0.2);
    }
  }

  :deep(.el-input__inner) {
    font-size: 14px;

    @media (max-width: 768px) {
      font-size: 16px; // 防止iOS缩放
    }
  }

  :deep(.el-input__suffix) {
    right: 12px;
  }
}

.enhanced-textarea {
  :deep(.el-textarea__inner) {
    padding-left: 40px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    transition: all 0.2s ease;
    resize: vertical;
    min-height: 80px;

    &:hover {
      box-shadow: 0 4px 12px rgba(0, 82, 204, 0.1);
    }

    &:focus {
      box-shadow: 0 4px 12px rgba(0, 82, 204, 0.2);
    }
  }
}

/* 状态组选择 */
.status-group-wrapper {
  display: flex;
  gap: 12px;
  align-items: center;
  width: 100%;

  @media (max-width: 768px) {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
}

.status-select {
  flex: 1;
}

.add-status-btn {
  border-radius: 6px;
  font-weight: 500;
  transition: all 0.2s ease;
  white-space: nowrap;

  &:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 82, 204, 0.3);
  }

  @media (max-width: 768px) {
    width: 100%;
  }

  .btn-icon {
    margin-right: 4px;
  }
}

/* 价格输入框 */
.price-wrapper {
  .price-unit {
    position: absolute;
    right: 12px;
    color: #6b7280;
    font-size: 14px;
    font-weight: 500;
    z-index: 1;
  }

  .price-input {
    :deep(.el-input__wrapper) {
      padding-right: 40px;
    }

    &.final-price {
      :deep(.el-input__wrapper) {
        background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
        border: 2px solid #f59e0b;
        font-weight: 600;
      }

      :deep(.el-input__inner) {
        color: #92400e;
        font-weight: 600;
        font-size: 16px;
      }
    }
  }
}

/* 产品清单 */
.product-content {
  background: transparent;
  border: none;
  box-shadow: none;
}

.enhanced-tabs {
  :deep(.el-tabs__header) {
    margin-bottom: 16px;
  }

  :deep(.el-tabs__nav-wrap) {
    background: #f8fafc;
    border-radius: 8px;
    padding: 4px;
  }

  :deep(.el-tabs__item) {
    border-radius: 6px;
    font-weight: 500;
    transition: all 0.2s ease;

    &.is-active {
      background: white;
      color: #0052cc;
      box-shadow: 0 2px 8px rgba(0, 82, 204, 0.15);
    }
  }

  :deep(.el-tabs__active-bar) {
    display: none;
  }
}

.product-form-wrapper {
  padding: 16px;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
}

/* 对话框底部 */
.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 20px 24px;
  background: white;

  @media (max-width: 768px) {
    padding: 16px;
    flex-direction: column;
    gap: 8px;
  }
}

.cancel-btn {
  border: 2px solid #e5e7eb;
  color: #6b7280;
  background: white;
  border-radius: 8px;
  padding: 10px 20px;
  font-weight: 500;
  transition: all 0.2s ease;
  min-height: 40px;

  &:hover {
    border-color: #d1d5db;
    color: #374151;
  }

  @media (max-width: 768px) {
    width: 100%;
    order: 2;
  }

  .btn-icon {
    margin-right: 6px;
  }
}

.confirm-btn {
  background: linear-gradient(135deg, #0052cc 0%, #1d4ed8 100%);
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  font-weight: 500;
  color: white;
  transition: all 0.2s ease;
  min-height: 40px;

  &:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 82, 204, 0.3);
  }

  &:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
  }

  @media (max-width: 768px) {
    width: 100%;
    order: 1;
  }

  .btn-icon {
    margin-right: 6px;
  }
}

/* 加载状态优化 */
:deep(.el-loading-mask) {
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(4px);
}

:deep(.el-loading-spinner) {
  .circular {
    width: 32px;
    height: 32px;
  }
}

/* 深色模式适配 */
@media (prefers-color-scheme: dark) {
  .dialog-content {
    background: #1f2937;
  }

  .form-container {
    background: #374151;
  }

  .form-section {
    background: #4b5563;
    border-color: #6b7280;

    &.product-section {
      background: #374151;
      border-color: #6b7280;
    }

    &.price-section {
      background: linear-gradient(135deg, #1e3a8a 0%, #1e40af 100%);
      border-color: #3b82f6;
    }
  }

  .section-title {
    color: #f9fafb;
  }

  .section-header {
    border-color: #60a5fa;
  }

  .section-icon {
    color: #60a5fa;
  }

  .enhanced-input,
  .enhanced-select,
  .enhanced-select-v2,
  .enhanced-date-picker,
  .enhanced-number {
    :deep(.el-input__wrapper) {
      background: #4b5563;
      border-color: #6b7280;

      .el-input__inner {
        color: #f9fafb;
      }
    }
  }

  .enhanced-textarea {
    :deep(.el-textarea__inner) {
      background: #4b5563;
      border-color: #6b7280;
      color: #f9fafb;
    }
  }

  .input-icon,
  .select-icon,
  .date-icon,
  .textarea-icon,
  .price-icon,
  .number-icon {
    color: #d1d5db;
  }

  .price-unit {
    color: #d1d5db;
  }

  .price-input {
    &.final-price {
      :deep(.el-input__wrapper) {
        background: linear-gradient(135deg, #92400e 0%, #b45309 100%);
        border-color: #f59e0b;
      }

      :deep(.el-input__inner) {
        color: #fbbf24;
      }
    }
  }

  .product-form-wrapper {
    background: #4b5563;
    border-color: #6b7280;
  }

  .enhanced-tabs {
    :deep(.el-tabs__nav-wrap) {
      background: #4b5563;
    }

    :deep(.el-tabs__item) {
      color: #d1d5db;

      &.is-active {
        background: #374151;
        color: #60a5fa;
      }
    }
  }

  .dialog-footer {
    background: #374151;
  }

  .enhanced-form {
    :deep(.el-form-item__label) {
      color: #f9fafb;
    }
  }

  :deep(.el-loading-mask) {
    background: rgba(55, 65, 81, 0.9);
  }
}

/* 高对比度模式适配 */
@media (prefers-contrast: high) {
  .enhanced-input,
  .enhanced-select,
  .enhanced-select-v2,
  .enhanced-date-picker,
  .enhanced-number {
    :deep(.el-input__wrapper) {
      border: 2px solid #0052cc;
      box-shadow: none;

      &:hover,
      &.is-focus {
        border-color: #1d4ed8;
        box-shadow: 0 0 0 2px rgba(0, 82, 204, 0.2);
      }
    }
  }

  .enhanced-textarea {
    :deep(.el-textarea__inner) {
      border: 2px solid #0052cc;
      box-shadow: none;

      &:hover,
      &:focus {
        border-color: #1d4ed8;
        box-shadow: 0 0 0 2px rgba(0, 82, 204, 0.2);
      }
    }
  }

  .cancel-btn {
    border: 2px solid #6b7280;
  }

  .confirm-btn {
    background: #0052cc;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  }
}

/* 减少动画模式适配 */
@media (prefers-reduced-motion: reduce) {
  .enhanced-input,
  .enhanced-select,
  .enhanced-select-v2,
  .enhanced-date-picker,
  .enhanced-textarea,
  .enhanced-number,
  .cancel-btn,
  .confirm-btn,
  .add-status-btn {
    transition: none;
  }

  .confirm-btn,
  .add-status-btn {
    &:hover {
      transform: none;
    }
  }
}

/* 触摸设备优化 */
@media (hover: none) and (pointer: coarse) {
  .enhanced-input,
  .enhanced-select,
  .enhanced-select-v2,
  .enhanced-date-picker,
  .enhanced-number {
    :deep(.el-input__wrapper) {
      min-height: 44px;
    }
  }

  .cancel-btn,
  .confirm-btn,
  .add-status-btn {
    min-height: 44px;
    padding: 12px 20px;
  }
}

/* 超小屏幕适配 */
@media (max-width: 480px) {
  .dialog-header {
    padding: 12px;
  }

  .form-container {
    padding: 12px;
  }

  .form-section {
    padding: 12px;
    margin-bottom: 12px;
  }

  .dialog-footer {
    padding: 12px;
  }

  .form-grid {
    gap: 12px;
  }

  .product-form-wrapper {
    padding: 12px;
  }
}

/* 横屏模式适配 */
@media (max-width: 768px) and (orientation: landscape) {
  .dialog-header {
    padding: 12px 16px;
    flex-direction: row;
    text-align: left;
  }

  .form-container {
    padding: 16px;
  }

  .form-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
  }

  .status-group-wrapper {
    flex-direction: row;
    align-items: center;
  }

  .status-group-item {
    grid-column: 1 / -1;
  }
}

/* 原有样式兼容 */
.groupStyle {
  :deep(.el-form-item__content) {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;

    @media (max-width: 768px) {
      flex-direction: column;
      align-items: stretch;
      gap: 8px;
    }
  }
}

.scroller {
  height: 200px;
  overflow-y: auto;

  &::-webkit-scrollbar {
    width: 6px;
  }

  &::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 3px;
  }

  &::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;

    &:hover {
      background: #94a3b8;
    }
  }
}
</style>
